package com.oos.zone.wechat.cp.service.handler;

import lombok.extern.log4j.Log4j2;
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

/**
 * 功能描述：客户群事件处理器
 *
 * @author 拓金辉
 * @version 1.0
 * @date 2021-07-31 18:18:18
 */
@Log4j2
@Service
public class WxCpChangeExternalChatMessageHandler extends AbstractWxCpMessageHandler {

    @Override
    public WxCpXmlOutMessage doHandle() {
        switch (wxMessage.getChangeType()) {
            case "create":
                return create();
            case "update":
                return update();
            case "dismiss":
                return dismiss();
            default:
                log.error("\n\n【事件类型未处理】\n\n {}", wxMessage.toString());
                return defaultTextMessage;
        }
    }

    public WxCpXmlOutMessage create() {
        CompletableFuture.runAsync(() -> log.info("客户群创建事件"), executor);
        return defaultTextMessage;
    }

    public WxCpXmlOutMessage update() {
        switch (wxMessage.getUpdateDetail()) {
            case "add_member":
                CompletableFuture.runAsync(() -> log.info("成员入群"), executor);
                return defaultTextMessage;
            case "del_member":
                CompletableFuture.runAsync(() -> log.info("成员退群"), executor);
                return defaultTextMessage;
            case "change_owner":
                CompletableFuture.runAsync(() -> log.info("群主变更"), executor);
                return defaultTextMessage;
            case "change_name":
                CompletableFuture.runAsync(() -> log.info("群名变更"), executor);
                return defaultTextMessage;
            case "change_notice":
                CompletableFuture.runAsync(() -> log.info("群公告变更"), executor);
                return defaultTextMessage;
            default:
                log.error("\n\n【UpdateDetail未处理】\n\n {}", wxMessage.toString());
                return defaultTextMessage;
        }
    }

    public WxCpXmlOutMessage dismiss() {
        CompletableFuture.runAsync(() -> log.info("客户群解散事件"), executor);
        return defaultTextMessage;
    }

}
